# sorted 函数
class Student:
    def __init__(self, name, sex, age, score):
        self.name = name
        self.sex = sex
        self.age = age
        self.score = score
    def __repr__(self):  # def __str__(self):
        '用于转化为字面值表达式'
        return f"Stduent('{self.name}', '{self.sex}', {self.age}, {self.score})"
class_1 = [
    Student('小张', '男', 18, 76),
    Student('小李', '女', 17, 80),
    Student('小王', '女', 19, 20),
    Student('小赵', '男', 16, 59),
]
# print(class_1)

scores = [8, 5, 2, 1, 3, 8, 9, 0, ]
L1 = sorted(scores)
print('L1:', L1)
L2 = sorted(scores, reverse=True)  # reverse=True，降序排序
print("L2:", L2)
# 根据学生排序
print(class_1)
def getkey(a_stu):
    return a_stu.age
# 按学生年龄，从小到大排序
L3 = sorted(class_1, key=getkey)
print('L3:', L3)
# 按学生年龄，从大到小排序
L3 = sorted(class_1, key=getkey, reverse=True)
print('L3:', L3)
# 按学生成绩，从大到小排序
L3 = sorted(
    class_1,
    key=lambda a_stu:a_stu.score,
    reverse=True)
print('L3:', L3)






